/*
* Copyright 2025 NXP
* NXP Proprietary. This software is owned or controlled by NXP and may only be used strictly in
* accordance with the applicable license terms. By expressly accepting such terms or by downloading, installing,
* activating and/or otherwise using the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms.  If you do not agree to be bound by the applicable license
* terms, then you may not retain, install, activate or otherwise use the software.
*/

#ifndef GUI_GUIDER_H
#define GUI_GUIDER_H
#ifdef __cplusplus
extern "C" {
#endif

#include "lvgl.h"
#include "lv_custom_focus.h"

//页计算: flash: 256k   (256 * 1024) / 4096 = 64页
//扇区计算:共64页
//起始地址 = 0x0800 0000 + (63 * 0x1000)= 0x0800 0000 + 0x0003 F000 = 0x0803 F000
// 结束地址 = 0x0803 F000 + 0x0000 0FFF = 0x0803 FFFF
#define FLASH_SAVE_ADDR  0x08000000 + (1024 * 254)		//设置FLASH 保存地址(必须为偶数，且其值要大于本代码所占用FLASH的大小+0X08000000)


#define BACKLIGHT_BLACK      0x141414
#define BACKLIGHT_GREEN      0X489E6E
#define BACKLIGHT_RED        0x791e33
#define BACKLIGHT_BLUE       0x1b4887   //0073c8

#if 0
// 键值功能定义
#define SNORING_POS_CMD             0X01        // 防鼾位置
#define LEISUER_POS_CMD             0X02        // 休闲位置
#define ZERO_G_POS_CMD              0X04        // 零重力位置

#define SET_M1_POS_CMD              0x200000    // M1记忆


#define BED_UP_CMD                  0X08        // 整床倾斜
#define BED_DOWN_CMD                0X010       // 整床倾斜恢复

#define HEAD_UP_CMD                 0X020       // 床头上升
#define HEAD_DOWN_CMD               0X080       // 床头下降

#define NECK_UP_CMD                 0X0200      // 颈部上升
#define NECK_DOWN_CMD               0x1000      // 颈部下降

#define LUMBAR_UP_CMD               0X0400      // 腰部上升
#define LUMBAR_DOWN_CMD             0x2000      // 腰部下降

#define FOOT_DOWN_CMD               0x4000      // 腿部下降
#define FOOT_UP_CMD                 0X0100      // 腿部上升

#define FLAT_POS_CMD                0x0800      // 平躺模式（相当于复位，床改平）


#define MASSAGE_10MIN_CMD           0X11000000
#define MASSAGE_20MIN_CMD           0X12000000
#define MASSAGE_30MIN_CMD           0X13000000

#define MASSAGE_MODE1_CMD           0X21000000
#define MASSAGE_MODE2_CMD           0X22000000
#define MASSAGE_MODE3_CMD           0X23000000
#define MASSAGE_MODE4_CMD           0X24000000

#define MASG_HEAD_INS1_CMD          0X31000000
#define MASG_HEAD_INS2_CMD          0X32000000
#define MASG_HEAD_INS3_CMD          0X33000000

#define MASG_FOOT_INS1_CMD          0X41000000
#define MASG_FOOT_INS2_CMD          0X42000000
#define MASG_FOOT_INS3_CMD          0X43000000

#define MASSAGE_CMD                 0X2000000      // 马达开关

#define LIGHT_CMD                   0X040       // 床灯

#define PUSHROD_RESET               0x01000000  // 隐藏功能（同时按下头部打开、收回，手动收回推杆）
#else 
// 键值功能定义
#define SNORING_POS_CMD             0X01        // 防鼾位置
#define LEISUER_POS_CMD             0X02        // 休闲位置
#define ZERO_G_POS_CMD              0X04        // 零重力位置

#define SET_M1_POS_CMD              0x200000    // M1记忆


#define BED_UP_CMD                  0X08        // 整床倾斜
#define BED_DOWN_CMD                0X010       // 整床倾斜恢复

#define HEAD_UP_CMD                 0X020       // 床头上升
#define HEAD_DOWN_CMD               0X080       // 床头下降

#define NECK_UP_CMD                 0X0200      // 颈部上升
#define NECK_DOWN_CMD               0x1000      // 颈部下降

#define LUMBAR_UP_CMD               0X0400      // 腰部上升
#define LUMBAR_DOWN_CMD             0x2000      // 腰部下降

#define FOOT_DOWN_CMD               0x4000      // 腿部下降
#define FOOT_UP_CMD                 0X0100      // 腿部上升

#define FLAT_POS_CMD                0x0800      // 平躺模式（相当于复位，床改平）

#define MASSAGE_LAST_TIMER_CMD           0x10000     // 上一个时间
#define MASSAGE_NEXT_TIMER_CMD           0x80000     // 下一个时间

#define MASSAGE_LAST_MODE_CMD            0X4000000     // 上一个模式
#define MASSAGE_NEXT_MODE_CMD            0X8000000      // 下一个模式

#define MASSAGE_HEAD_INS_UP_CMD     0x8000      // 按摩头部加强
#define MASSAGE_HEAD_INS_DOWN_CMD   0x40000     // 按摩头部降低

#define MASSAGE_FOOT_INS_UP_CMD     0x20000     // 按摩腿部加强
#define MASSAGE_FOOT_INS_DOWN_CMD   0x100000    // 按摩腿部降低

#define MASSAGE_CMD                 0X2000000      // 马达开关

#define LIGHT_CMD                   0X040       // 床灯

#define PUSHROD_RESET               0x01000000  // 隐藏功能（同时按下头部打开、收回，手动收回推杆）

#endif




typedef enum {
    HOME = 0,
    WHITE,
    RED,
    BLACK,
    BLUE,
} theme_t;


typedef struct
{
	lv_obj_t *main;
	bool main_del;
	lv_obj_t *main_btn_1;
	lv_obj_t *main_btn_1_label;
	lv_obj_t *main_btn_2;
	lv_obj_t *main_btn_2_label;
	lv_obj_t *main_btn_3;
	lv_obj_t *main_btn_3_label;
	lv_obj_t *main_btn_4;
	lv_obj_t *main_btn_4_label;
	lv_obj_t *motion_1;
    lv_obj_t *cont;
	bool motion_1_del;
	lv_obj_t *motion_1_label_1;
	lv_obj_t *motion_1_mot_pos_img;
	lv_obj_t *motion_1_btn_1;
	lv_obj_t *motion_1_btn_1_label;
	lv_obj_t *motion_2;
	bool motion_2_del;
	lv_obj_t *motion_2_mem_pos_img;
	lv_obj_t *motion_2_label_1;
	lv_obj_t *settings_1;
	bool settings_1_del;
	lv_obj_t *settings_1_bar_1;
	lv_obj_t *settings_1_btn_minus;
	lv_obj_t *settings_1_btn_minus_label;
	lv_obj_t *settings_1_btn_plus;
	lv_obj_t *settings_1_btn_plus_label;
	lv_obj_t *settings_1_label_1;
	lv_obj_t *settings_1_label_2;
	lv_obj_t *settings_1_btn_3;
	lv_obj_t *settings_1_btn_3_label;
	lv_obj_t *settings_1_btn_4;
	lv_obj_t *settings_1_btn_4_label;
	lv_obj_t *settings_1_btn_5;
	lv_obj_t *settings_1_btn_5_label;
	lv_obj_t *settings_1_btn_6;
	lv_obj_t *settings_1_btn_6_label;
	lv_obj_t *settings_1_label_value;
	lv_obj_t *light_1;
	bool light_1_del;
	lv_obj_t *light_1_img_1;
    lv_obj_t *light_1_btn_1;
	lv_obj_t *light_1_label_1;
	lv_obj_t *massage_1;
	bool massage_1_del;
	lv_obj_t *massage_1_btn_4;
	lv_obj_t *massage_1_btn_4_label;
	lv_obj_t *massage_1_btn_3;
	lv_obj_t *massage_1_btn_3_label;
	lv_obj_t *massage_1_btn_2;
	lv_obj_t *massage_1_btn_2_label;
	lv_obj_t *massage_1_btn_1;
	lv_obj_t *massage_1_btn_1_label;
	lv_obj_t *massage_onoff;
	bool massage_onoff_del;
	lv_obj_t *massage_onoff_btn_1;
	lv_obj_t *massage_onoff_btn_1_label;
	lv_obj_t *massage_time;
	bool massage_time_del;
	lv_obj_t *massage_time_roller_1;
	lv_obj_t *massage_mode;
	bool massage_mode_del;
	lv_obj_t *massage_mode_roller_1;
	lv_obj_t *massage_intensity;
	bool massage_intensity_del;
    lv_obj_t *massage_intensity_label_1;
	lv_obj_t *massage_intensity_roller_1;
	lv_obj_t *light_2;
	bool light_2_del;
	lv_obj_t *light_2_btn_1;
	lv_obj_t *light_2_btn_1_label;

	lv_obj_t *enter_pair;
	bool enter_pair_del;
	// lv_obj_t *light_3_btn_1;
	lv_obj_t *enter_pair_1_label;
	// lv_obj_t *enter_pair_2_label;
	lv_obj_t *low_bat;
	bool low_bat_del;
	lv_obj_t *low_bat_1_label;
    struct {
        uint32_t button;
        uint32_t font;
        uint32_t border;
        uint32_t backlight;
    } color;

    struct {
        uint8_t foot;
    } msg_intensity_pos;

}lv_ui;

typedef struct {
    lv_ui *ui;
} ui_context_t;

/* 全局背光状态标志位*/
typedef union {
    uint32_t sta;
    struct {
        uint32_t led : 1;

        uint32_t msg_head_ins0 : 1;
        uint32_t msg_head_ins1 : 1;
        uint32_t msg_head_ins2 : 1;

        uint32_t msg_foot_ins0 : 1;
        uint32_t msg_foot_ins1 : 1;
        uint32_t msg_foot_ins2 : 1;

        uint32_t msg_mode1 : 1;
        uint32_t msg_mode2 : 1;
        uint32_t msg_mode3 : 1;
        uint32_t msg_mode4 : 1;

        uint32_t msg_min10 : 1;
        uint32_t msg_min20 : 1;
        uint32_t msg_min30 : 1;

        uint32_t msg_on_off : 1;
        uint32_t : 17;
    } bits;
} backlight_union_t;

extern backlight_union_t backlight;


typedef void (*ui_setup_scr_t)(lv_ui * ui);

void ui_init_style(lv_style_t * style);

void ui_load_scr_animation(lv_ui *ui, lv_obj_t ** new_scr, bool new_scr_del, bool * old_scr_del, ui_setup_scr_t setup_scr,
                           lv_scr_load_anim_t anim_type, uint32_t time, uint32_t delay, bool is_clean, bool auto_del);

void ui_animation(void * var, int32_t duration, int32_t delay, int32_t start_value, int32_t end_value, lv_anim_path_cb_t path_cb,
                       uint16_t repeat_cnt, uint32_t repeat_delay, uint32_t playback_time, uint32_t playback_delay,
                       lv_anim_exec_xcb_t exec_cb, lv_anim_start_cb_t start_cb, lv_anim_ready_cb_t ready_cb, lv_anim_deleted_cb_t deleted_cb);


void init_scr_del_flag(lv_ui *ui);

void setup_ui(lv_ui *ui);

void init_keyboard(lv_ui *ui);

void update_ui_timer_cb(lv_timer_t *timer);

extern lv_ui guider_ui;


void setup_scr_main(lv_ui *ui);
void setup_scr_motion_1(lv_ui *ui);
void setup_scr_motion_2(lv_ui *ui);
void setup_scr_settings_1(lv_ui *ui);
void setup_scr_light_1(lv_ui *ui);
void setup_scr_low_bat(lv_ui *ui);
void setup_scr_enter_pair(lv_ui *ui);
void setup_scr_massage_1(lv_ui *ui);
void setup_scr_massage_onoff(lv_ui *ui);
void setup_scr_massage_time(lv_ui *ui);
void setup_scr_massage_mode(lv_ui *ui);
void setup_scr_massage_intensity(lv_ui *ui);
void Setup_Rx_Sta(lv_ui *ui);
void Pair_Txt_Sta(lv_ui *ui, uint8_t sta);
LV_FONT_DECLARE(lv_font_montserrat_14)
// LV_FONT_DECLARE(lv_font_montserrat_16)
// LV_FONT_DECLARE(lv_font_montserrat_12)
LV_FONT_DECLARE(lv_font_montserrat_18)
// LV_FONT_DECLARE(lv_font_montserrat_48)


#ifdef __cplusplus
}
#endif
#endif
